/***************************************************************************************
 *
 *  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 *
 *  By downloading, copying, installing or using the software you agree to this license.
 *  If you do not agree to this license, do not download, install, 
 *  copy or use the software.
 *
 *  Copyright (C) 2014-2019, Happytimesoft Corporation, all rights reserved.
 *
 *  Redistribution and use in binary forms, with or without modification, are permitted.
 *
 *  Unless required by applicable law or agreed to in writing, software distributed 
 *  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
 *  language governing permissions and limitations under the License.
 *
****************************************************************************************/

#ifndef	DIGCALC_H
#define	DIGCALC_H

#include "rfc_md5.h"

#ifdef __cplusplus
extern "C" {
#endif

#define IN
#define OUT

/* calculate H(A1) as per HTTP Digest spec */
void DigestCalcHA1(
	IN const char * pszAlg,
	IN const char * pszUserName,
	IN const char * pszRealm,
	IN const char * pszPassword,
	IN const char * pszNonce,
	IN const char * pszCNonce,
	OUT HASHHEX SessionKey
);
void DigestCalcHA2(
		IN const char *pszMthod,
		IN const char *pszUri,
		OUT HASHHEX SessionKey);
void DigestCalcHA2_AuthInit(
		IN const char *pszMthod,
		IN const char *pszUri,
		OUT HASHHEX SessionKey);
void DigestCalcResponseHash(
	IN HASHHEX HA1, /* H(A1) */
	IN const char * pszNonce, /* nonce from server */
	IN const char * pszNonceCount, /* 8 hex digits */
	IN const char * pszCNonce, /* client nonce */
	IN const char * pszQop, /* qop-value: "", "auth", "auth-int" */
	IN const char * pszMethod, /* method from the request */
	IN const char * pszDigestUri, /* requested URL */
	IN HASHHEX HEntity, /* H(entity body) if qop="auth-int" */
	OUT HASH  RespHash /* request-digest or response-digest */
);

void DigestCalcResponse(
	IN HASHHEX HA1, /* H(A1) */
	IN const char * pszNonce, /* nonce from server */
	IN const char * pszNonceCount, /* 8 hex digits */
	IN const char * pszCNonce, /* client nonce */
	IN const char * pszQop, /* qop-value: "", "auth", "auth-int" */
	IN const char * pszMethod, /* method from the request */
	IN const char * pszDigestUri, /* requested URL */
	IN HASHHEX HEntity, /* H(entity body) if qop="auth-int" */
	OUT HASHHEX Response /* request-digest or response-digest */
);
void
DigestCalcResponse2(
		IN HASHHEX SessionKey1,
		IN const char *pszUri,
		IN HASHHEX SessionKey2,
		OUT HASHHEX Response);
void
DigestCalcResponse3(//(HA1, szNonce, sznc, szcnonce, szQop, HA2, Response)
		IN HASHHEX SessionKey1,
		IN const char *pszNonce,
		IN const char *psznc,
		IN const char *pszcnonce,
		IN const char *pszQop,
		IN HASHHEX SessionKey2,
		OUT HASHHEX Response);

#ifdef __cplusplus
}
#endif

#endif	//	DIGCALC_H


